<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .con {
            width:500px;
            border:2px solid rgb(251, 6, 6);
            margin:0 auto;
            overflow:hidden;
        }
        .con .item{
            width:100px;
            height:100px;
            text-align:center;
            float:left;
        }
    </style>
</head>
<body>
    <div class = "con" id="con">
        <div class="item">
            <img src="images/animal1.png" />
        </div>
        <div class="item">
            <img src="images/animal2.png" />
        </div>
        <div class="item">
            <img src="images/animal3.png" />
        </div>
        <div class="item">
            <img src="images/animal4.png" />
        </div>
    </div>
</body>
<script>
   var con = document.getElementById("con");
   
    /**
     * 根据元素的class属性值来获取对应的网页元素的DOM节点对象
     */
   var itemList = con.getElementsByClassName("item");
   for(var i = 0; i < itemList.length; i++){
    itemList[i].onclick = function(){
        this.style.backgroundColor = "red";
    }
   }
</script>
</html>